package com.arnold.guide.sparkSql.demo06

import org.apache.spark.sql.{DataFrame, SparkSession}

/**
  * Created by arnold.zhu on 2017/7/24.
  */
object Demo06 {

  private val sparkSession: SparkSession = SparkSession.builder().master("local[3]").appName("LearnSparkSQL").getOrCreate()


  def main(args: Array[String]): Unit = {
    val path: String = Thread.currentThread().getContextClassLoader.getResource("sparksql/demo06/person.json").getPath

    import sparkSession.implicits._

    // 读取json 可以是一个文件 或者 json字符串
    val personDF: DataFrame = sparkSession.read.json(path)

    personDF.printSchema()

    personDF.createTempView("people")

    // 查询id小于3的记录
    sparkSession.sql("select * from people where id < 3").show()

  }

}
